/**
 * 
 */
package com.gragra.nounIdentification;
/**
 * this class is used to implement convergence testing by assessing the ratio of word types covered
 * by the current candidate words, while this is less dependent on the corpus size, it is not completely
 * robust to corpus size variations, since function words for example may cover less and less types 
 * as a corpus gets bigger
 * @author Christoph Teichmann
 * created Mar 26, 2013 10:28:19 AM
 * @version 0.1
 */
public class ConvergenceByTypeCoverage implements ConvergenceAssessment
{
	/**
	 * creates a new instance that will signal convergence once the given ratio has been reached
	 * @param intendedRatio
	 */
	public ConvergenceByTypeCoverage(double intendedRatio)
	{this.intendedRatio = intendedRatio;}
	/**
	 * the ratio that is intended
	 */
	private final double intendedRatio;
	/* (non-Javadoc)
	 * @see com.gragra.nounIdentification.ConvergenceAssessment#hasConverged(int, com.gragra.nounIdentification.NounIdentifier)
	 */
	@Override
	public boolean hasConverged(int iterations, NounIdentifier nounIdentifier)
	{
		if(iterations > 0)
		{
			double ratio =  nounIdentifier.calculateWordTypeCoverage();
			return ratio > intendedRatio;
		}
		else
		{return false;}
	}
}